package dao;

import model.User;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class UserDaoImpl {
    public void writeUser(User user){
        try {
        	System.out.println("1");
            String url = "jdbc:mysql://localhost:3306/pvz";
            String userName = "root";
            String password = "";
            ResultSet rs = null;
            Statement stmt = null;
            Connection con = DriverManager.getConnection(url, userName, password);
            
            String sql = "insert into user(User,Pass) values(?,?)";
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, user.getAdmin());
            ps.setString(2, user.getPass());
            System.out.println("write");
            ps.executeUpdate();
            con.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public List<User> readUser(){
        List<User> userList = new ArrayList<>();

        try {
            String url = "jdbc:mysql://localhost:3306/pvz";
            String sql = "select * from user";
            String userName = "root";
            String password = "";
            ResultSet rs = null;
            Statement stmt = null;
            Connection con = DriverManager.getConnection(url, userName, password);
            PreparedStatement ps = con.prepareStatement(sql);

        } catch (SQLException e) {
            e.printStackTrace();
        }


        return userList;
    }
}
